<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of UtilAction
 *
 * @author ASIMO
 */
class UtilAction extends Action{
    
    public function _empty() {
        $tpl = "../Include/App/Group/Bridge/Tpl/Public_404.html";
        $this->display($tpl);
    }
    
    public function uploadimg() {
        header("Content-Type:text/html; charset=utf-8"); //不然返回中文乱码		
        import('ORG.Net.UploadFile');
        $upload = new UploadFile(); // 实例化上传类
        $upload->maxSize = 1048576; // 设置附件上传大小	
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->savePath = 'Uploads/temp/';
        if (!file_exists($upload->savePath)) {
            mkdir($upload->savePath, 0777, true);
        }
        $ret = $upload->upload();
        if (!$ret) {// 上传错误提示错误信息
            Log::write(">>>>>>>>>上传失败！");
            $msg = $upload->getErrorMsg();
            echo json_encode(array("success"=>0,"msg"=>"无效文件类型"));
            exit;
        } else {
            Log::write(">>>>>>>>>上传成功！");
            $info = $upload->getUploadFileInfo();
            $url = $upload->savePath . $info[0]['savename'];
            //检查尺寸
            $imgdata = getimagesize($url);
            if ($imgdata[0]<300 || $imgdata[1]<300) {
                unlink($url);//删除未采用的文件
                ajaxf('尺寸小于300*300像素，不适合用作头像');
            }
            
            $name = $info[0]['name'];

            echo json_encode(array("success"=>1,"url"=>$url));
            exit;
        }
    }
    
    //上传作品图片
    public function uploadwork() {
        header("Content-Type:text/html; charset=utf-8"); //不然返回中文乱码		
        import('ORG.Net.UploadFile');
        $upload = new UploadFile(); // 实例化上传类
        $upload->maxSize = 1048576; // 设置附件上传大小	
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->savePath = 'Uploads/temp/'; // 设置附件上传目录,按月份保存图片
        if (!file_exists($upload->savePath)) {
            mkdir($upload->savePath, 0777, true);
        }
        $ret = $upload->upload();
        if (!$ret) {// 上传错误提示错误信息
            Log::write(">>>>>>>>>上传失败！");
            $msg = $upload->getErrorMsg();
            echo json_encode(array("success"=>0,"msg"=>"无效文件类型"));
            exit;
        } else {
            Log::write(">>>>>>>>>上传成功！");
            $info = $upload->getUploadFileInfo();
            $url = $upload->savePath . $info[0]['savename'];
            $name = $info[0]['name'];

            echo json_encode(array("success"=>1,"url"=>$url));
            exit;
        }
    }
    
    //裁剪上传的图片,覆盖原文件
    public function cutImg() {
        $url = I('url');
        $x = I('x');
        $y = I('y');
        $w = I('w');
        $h = I('h');
        if (substr($url, 0, 1)==='/') {
            $url = substr($url, 1);
        }
        if (!create_image($url, $url, $x, $y, $w, $h)) {
            ajaxf('裁剪失败!');
        }
        echo json_encode(array('success'=>1, 'url'=>$url));
    }
    
    //根据卡号查询银行
    public function getbank() {
        $cardno = I('card');
        if (!$cardno) {
            ajaxf("参数错误!");
        }
        $bl = require_once APP_PATH."Lib/bankList.php";
        echo json_encode(bankInfo($cardno, $bl));
    }
}

?>